<template>
    
    <popup
        ref="popupRef"
        width="830px"
        :title="props.popupTitles"
        :async="true"
        @confirm="handleConfirm"
        @close="handleClose"
    >
        
        
        <slot></slot>
        
        <div class="flex  items-center justify-center">
            <div>
                <el-transfer
                    v-model="value"
                    :titles="props.titles"
                    :data="formData"
                    :props=props.props>
                
                </el-transfer>
            </div>
        </div>
    </popup>
</template>

<script lang="ts" setup>
import {AfterSaleItemMaterialDTO} from "@/api/afterSale/order/dto/AfterSaleItemMaterialDTO";

const props = withDefaults(defineProps<{
    popupTitles?: string
    titles?: string []
    props?: any
}>(), {
    titles: () => ['可发出物料', '确定发出物料'],
    props: {
        key: 'afterSaleOrderLineId',
        label: 'itemCode'
        
    },
    popupTitles: "发运单组装"
})


let popupRef = shallowRef();
const formData = ref<AfterSaleItemMaterialDTO []>([])
const value = ref([]);


let emits = defineEmits(["confirm", "close"]);

/**
 *  确定
 *
 * @author 徐寿春
 * 2023/4/24 09:15
 */
function handleConfirm() {
    emits("confirm", value.value)
}

/**
 * 取消
 *
 * @author 徐寿春
 * 2023/4/24 09:17
 */
function handleClose() {
    emits("close")
}


function close() {
    popupRef.value.close()
}

/**
 * 打开transfer
 *
 * @author 徐寿春
 * 2023/4/24 09:31
 */
function openTransfer(afterSaleItemLineList?: any[]) {
    if (afterSaleItemLineList) {
        formData.value = afterSaleItemLineList
    }
    popupRef.value.open()
}


/**
 * 赋值
 *
 * @author 徐寿春
 * 2023/4/25 11:25
 */
function seTransferDate(afterSaleItemLineList?: any[]) {
    if (afterSaleItemLineList) {
        formData.value = afterSaleItemLineList
    } else {
        formData.value = []
        value.value = []
    }
}

defineExpose({
    openTransfer,
    seTransferDate,
    close
})


</script>
